home *** CD-ROM | disk | FTP | other *** search
- // File "indent LDEF.c" - LDEF that lets you indented text within a cell
- // This code is placed in the public domain for free use and distribution - MJS
- //
- // 6/27/95 Changed the Hilite Mode to use accessor functions
- // Properly save and restore Handle states - MJS
- //
- // 10/16/93 First released the LDEFs to the net - MJS
- //
- // 5/23/91 Original snippet which this is shamelessly based on,
- // by Steven Falkenburg, Apple DTS
-
- // * **************************************************************************** * //
-
- #include <GestaltEqu.h>
- #include <Icons.h>
-
- // * **************************************************************************** * //
- // * **************************************************************************** * //
- // Universal Headers users can replace these with LM accessor functions
-
- pascal unsigned char GetHiliteMode(void) = { 0x1EB8, 0x0938 }; /* MOVE.B 0x0938,(A7) */
- pascal void SetHiliteMode(unsigned char) = { 0x11DF, 0x0938 }; /* MOVE.B (A7)+,0x0938 */
-
- // * **************************************************************************** * //
- // * **************************************************************************** * //
- // Spacing Constants
-
- #define kLeftOffset 2
- #define kTopOffset 0
-
- // * **************************************************************************** * //
-
- pascal void main(short message, Boolean hilited, Rect *cellRect, Cell theCell,
- short dataOffset, short dataLen, ListHandle theList) {
- short leftDraw,topDraw;
- Ptr cellData;
- ListPtr theListPtr;
- SignedByte hStateList, hStateCells;
- FontInfo fontInfo;
-
- // Lock down the handles
- hStateList = HGetState((Handle) theList);
- HLock((Handle) theList);
- theListPtr = *theList;
- hStateCells = HGetState((Handle) theListPtr->cells);
- HLock((Handle) theListPtr->cells);
- cellData = *(theListPtr->cells);
-
- switch (message) {
- case lInitMsg:
- break;
-
- case lDrawMsg:
- EraseRect(cellRect);
-
- if (dataLen > 0) {
- leftDraw = cellRect->left + theListPtr->indent.h + kLeftOffset;
- topDraw = cellRect->top + theListPtr->indent.v + kTopOffset;
-
- // Determine the indent and add it...
- while (cellData[dataOffset] == '\t') {
- dataOffset += 1;
- dataLen -= 1;
- leftDraw += 12;
- }
-
- GetFontInfo(&fontInfo);
- MoveTo(leftDraw, topDraw + fontInfo.ascent);
-
- // Condense if the text doesnt fit
- TextFace(0);
- if (TextWidth(cellData, dataOffset, dataLen) > (cellRect->right - leftDraw))
- TextFace(condense);
-
- DrawText(cellData, dataOffset, dataLen);
- }
-
- if (!hilited) break;
-
- case lHiliteMsg:
- SetHiliteMode(GetHiliteMode() ^ (1L << hiliteBit));
- InvertRect(cellRect);
- break;
-
- case lCloseMsg:
- break;
- }
-
- HSetState((Handle) theListPtr->cells,hStateCells);
- HSetState((Handle) theList, hStateList);
- }
-